package com.day1020;

import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * 音乐播放的线程类
 */
public class SoundPool extends Thread {

    public static final String BG_MUSIC = "game_music.wav";
    public static final String SHOOT = "bullet.wav";
    public static final String BOOM = "enemy0_down.wav";
    AudioClip ac;
    public SoundPool(String path){
        try {
            File file = new File("D:\\IDEA\\lzy_java\\src\\main\\java\\com\\day1020\\musics\\"+path);
            //URL url =  this.getClass().getResource("D:\\IDEA\\lzy_java\\src\\main\\java\\com\\day1020\\musics\\"+path);
            URL url = file.toURL();
            ac =  Applet.newAudioClip(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    public void play(){
        ac.play();
    }
    public void stopAc(){
        ac.stop();
    }
    public void loop(){
        ac.loop();
    }

    @Override
    public void run() {
        play();
    }
}
